package com.hy.mydesktop.client.component.factory;

import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.hy.mydesktop.client.component.meta.CheckBoxModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
/**
 * 
 * <ul>
 * <li>开发作者：冬超</li>
 * <li>设计日期：2010-8-30；时间：上午09:37:13</li>
 * <li>类型名称：CheckBoxFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class CheckBoxFactory {
	public static CheckBox createCheckBox(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		
		return configureCheckBox(gxtComponentMetaNodeModel);

	}

	/**
	 * 
	 * 
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static CheckBox configureCheckBox(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {

		CheckBox checkBox = createDefaultCheckBox();
		checkBox = AbstractComponetFactory.configureAbstractComponet(checkBox, gxtComponentMetaNodeModel);
		
		if (gxtComponentMetaNodeModel.get(CheckBoxModelEnum.BOXLABEL
				.name().toLowerCase()) != null) {
			String boxLabel = (String) gxtComponentMetaNodeModel
					.get(CheckBoxModelEnum.BOXLABEL.name().toLowerCase());
			checkBox.setBoxLabel(boxLabel);

		}
		if (gxtComponentMetaNodeModel.get(CheckBoxModelEnum.NAME
				.name().toLowerCase()) != null) {
			String name = (String) gxtComponentMetaNodeModel
					.get(CheckBoxModelEnum.NAME.name().toLowerCase());
			checkBox.setName(name);

		}
		if (gxtComponentMetaNodeModel.get(CheckBoxModelEnum.FIELDLABEL
				.name().toLowerCase()) != null) {
			String fieldLabel = (String) gxtComponentMetaNodeModel
					.get(CheckBoxModelEnum.FIELDLABEL.name().toLowerCase());
			checkBox.setFieldLabel(fieldLabel);

		}
		if (gxtComponentMetaNodeModel.get(CheckBoxModelEnum.READONLY
				.name().toLowerCase()) != null) {
			Boolean readOnly = (Boolean) gxtComponentMetaNodeModel
					.get(CheckBoxModelEnum.READONLY.name().toLowerCase());
			checkBox.setReadOnly(readOnly);

		}
		if (gxtComponentMetaNodeModel.get(CheckBoxModelEnum.VALUE
				.name().toLowerCase()) != null) {
			Boolean value = (Boolean) gxtComponentMetaNodeModel
					.get(CheckBoxModelEnum.VALUE.name().toLowerCase());
			checkBox.setValue(value);

		}

		return checkBox;
	}

	private static CheckBox createDefaultCheckBox() {

		CheckBox checkBox = new CheckBox();
		return checkBox;
	}
}
